package com.yinhai.msg.thirdPlatform.rest;

import com.alibaba.fastjson.JSONObject;
import com.yinhai.msg.thirdPlatform.service.read.MsgThirdPlatformReadService;
import com.yinhai.msg.thirdPlatform.service.write.MsgThirdPlatformWriteService;
import com.yinhai.msg.thirdPlatform.vo.MsgThirdPlatformVo;
import com.yinhai.ta404.core.restservice.BaseRestService;
import com.yinhai.ta404.core.restservice.annotation.RestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhongrd
 * @file 第三方平台配置
 * @date 2019/5/20 17:11
 */
@RestService({"msg/thirdPlatform"})
@Validated
public class MsgThirdPlatformRestService extends BaseRestService {
    @Autowired
    private MsgThirdPlatformWriteService msgThirdPlatformWriteService;
    @Autowired
    private MsgThirdPlatformReadService msgThirdPlatformReadService;
    /**
    * 新增第三方平台配置
     * @param msgThirdPlatformVoList,platformtype
    */
    @PostMapping("thirdPlatformController/add.do")
    public void add(String msgThirdPlatformVoList,String platformtype,String platformname){
        List<MsgThirdPlatformVo> thirdPlatformVoList = JSONObject.parseArray(msgThirdPlatformVoList,MsgThirdPlatformVo.class);
        //每个平台有多个属性,循环插入
        for (MsgThirdPlatformVo msgThirdPlatformVo:thirdPlatformVoList){
            msgThirdPlatformVo.setPlatformtype(platformtype);
            msgThirdPlatformVo.setCreateUser(getCurUserId());
            msgThirdPlatformVo.setPlatformname(platformname);
            msgThirdPlatformWriteService.add(msgThirdPlatformVo);
        }
    }
    /**
    * 分组查询第三方平台
     * @param
    */
    @PostMapping("thirdPlatformController/query.do")
    public void query(){
        List<Map<String,Object>> msgThirdPlatformVos = msgThirdPlatformReadService.queryThirdPlatForm(new HashMap());
        this.setData("msgThirdPlatform",msgThirdPlatformVos);
    }

    /**
     * 删除第三方平台
     * @param id
     */
    @PostMapping("thirdPlatformController/delete.do")
    public void delete(String id){
        String[] ids = id.split(",");
        msgThirdPlatformWriteService.deletePlatForm(ids);
    }
}
